import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {HttpServicesProvider} from "../../providers/http-services/http-services";
import {ValidateProvider} from "../../providers/validate/validate";
import {ConfigProvider} from "../../providers/config/config";
import {UtilsProvider} from "../../providers/utils/utils";

@IonicPage({
    segment: 'member/resume',
    defaultHistory: ['MemberPage']
})
@Component({
    selector: 'page-person-resume',
    templateUrl: 'person-resume.html',
})
export class PersonResumePage {
    token: string;
    resume = {};
    hasResume:boolean = false;
    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public httpService: HttpServicesProvider,
        public validate: ValidateProvider,
        public config: ConfigProvider,
        public util: UtilsProvider
    ) {
        if (!this.validate.checkLogin()) {
            this.navCtrl.push('LoginPage');
        }
    }

    //判断用户是否登录
    ionViewCanEnter(){
        return this.validate.checkLogin();
    }

    ionViewDidLoad() {
        this.token = this.config.getToken();
        this.getResume();
    }

    getResume() {
        let apiUrl = "/user_info/my_resume_detail/token/" + this.token;
        this.httpService.requestData(apiUrl, response => {
            if (response['error'] === 200) {
                this.resume = response['data'];
                this.hasResume = true;
            } else if(response['error'] === 201) {
                this.hasResume = false;
                return false;
            }else{
                this.util.presentAlert(response['message']);
            }
        });
    }

}
